/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gr.uop.cst.context.base;

import java.io.Serializable;
import java.util.Comparator;

/**
 *
 * @author Ioannis Bourlakos &lt;mi49@uop.gr&gt;
 */
public abstract class ReversibleContextSourceComparator implements Comparator<ContextSource>, Serializable {
    private boolean reversed = false;

    public ReversibleContextSourceComparator toggleReversed() {
        this.reversed = !this.reversed;
        return this;
    }

    public boolean isReversed() {
        return this.reversed;
    }

    @Override
    public int compare(ContextSource o1, ContextSource o2) {
        return initialCompare(o1, o2) * ((this.reversed) ? (-1) : 1);
    }

    public abstract int initialCompare(ContextSource o1, ContextSource o2);
    
}
